package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.time.LocalDateTime;

public class AdminProfilePasswordServiceImpl implements AdminProfilePasswordService{
    @Override
    public boolean profilePassword(MarketAdmin admin, String s2) {
        SqlSession session = MybatisUtils.getSession();
        try {
            MarketAdminMapper mapper = session.getMapper(MarketAdminMapper.class);
            admin.setPassword(s2);
            admin.setUpdateTime(LocalDateTime.now());
            int i = mapper.updateByPrimaryKey(admin);
            session.commit();
            session.close();
            if (i!=0){
                return true;
            }
        }catch (Exception e){
            session.rollback();
            e.printStackTrace();
        }finally {
            session.close();
        }

        return false;
    }
}
